<script language="javascript">
function validate_form(thisform)
{
with (thisform)
{
	
	
	if (validate_required(txtmonth,"Bạn chưa chọn tháng !")==false)
 	{txtmonth.focus();return false;}
	
	if (validate_required(txtyear,"Bạn chưa chọn năm !")==false)
 	{txtyear.focus();return false;}
	if (validate_required(nhanvien,"Bạn chưa chọn nhân viên !")==false)
 	{nhanvien.focus();return false;}
	

}
}
</script>
 <table class="box-vang5" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr class="light">
          <td class="text-top">.:. Báo cáo công việc</td>
        </tr>
      </tbody></table>
      <table class="box-vang5" cellpadding="0" cellspacing="0" width="100%">
        <tbody><tr class="light">
          <td class="t-l"></td>
          <td class="t-c"></td>
          <td class="t-r"></td>
        </tr>
        <tr class="light">
          <td class="c-l"></td>
          <td class="c-c" valign="top">
   
  <div class="clear" style="height:10px"></div>
 <div id="noidung-tab1">
     <form method="post" action="" onsubmit="return validate_form(this);">
     <p>Xem báo cáo  <span>
     	<select name="txtmonth"> 
        	<option value="">--Chọn tháng--</option>
            <option value="01" <?php if($_POST['txtmonth']==1){?> selected="selected" <?php }?>> 01 </option>
            <option value="02" <?php if($_POST['txtmonth']==2){?> selected="selected" <?php }?>> 02 </option>
            <option value="03" <?php if($_POST['txtmonth']==3){?> selected="selected" <?php }?>> 03 </option>
            <option value="04" <?php if($_POST['txtmonth']==4){?> selected="selected" <?php }?>> 04 </option>
            <option value="05" <?php if($_POST['txtmonth']==5){?> selected="selected" <?php }?>> 05 </option>
            <option value="06" <?php if($_POST['txtmonth']==6){?> selected="selected" <?php }?>> 06 </option>
            <option value="07" <?php if($_POST['txtmonth']==7){?> selected="selected" <?php }?>> 07 </option>
            <option value="08" <?php if($_POST['txtmonth']==8){?> selected="selected" <?php }?>> 08 </option>
            <option value="09" <?php if($_POST['txtmonth']==9){?> selected="selected" <?php }?>> 09 </option>
            <option value="10" <?php if($_POST['txtmonth']==10){?> selected="selected" <?php }?>> 10 </option>
            <option value="11" <?php if($_POST['txtmonth']==11){?> selected="selected" <?php }?>> 11 </option>
            <option value="12" <?php if($_POST['txtmonth']==12){?> selected="selected" <?php }?>> 12 </option>
        </select>
    </span> 
    <span>Năm </span> 
    <span> 
    	<select name="txtyear"> 
        	<option value="">--Chọn năm--</option>
            <option value="2012" <?php if($_POST['txtyear']==2012){?> selected="selected" <?php }?>>2012 </option>
            <option value="2013" <?php if($_POST['txtyear']==2013){?> selected="selected" <?php }?>>2013 </option>
            <option value="2014" <?php if($_POST['txtyear']==2014){?> selected="selected" <?php }?>>2014 </option>
            <option value="2015" <?php if($_POST['txtyear']==2015){?> selected="selected" <?php }?>>2015 </option>
            <option value="2016" <?php if($_POST['txtyear']==2016){?> selected="selected" <?php }?>>2016 </option>
            <option value="2017" <?php if($_POST['txtyear']==2017){?> selected="selected" <?php }?>>2017 </option>
            <option value="2018" <?php if($_POST['txtyear']==2018){?> selected="selected" <?php }?>>2018 </option>
            <option value="2019" <?php if($_POST['txtyear']==2019){?> selected="selected" <?php }?>>2019 </option>
            <option value="2020" <?php if($_POST['txtyear']==2020){?> selected="selected" <?php }?>>2020 </option>
        </select>
    </span> 
    <?php if($_SESSION['level']==2 or $_SESSION['level']==3){?>
    &nbsp;&nbsp;
    |
    &nbsp;&nbsp;
    <span>Nhân viên </span> 
    <span> 
    	<select name="nhanvien"> 
        	<option value="">--Chọn nhân viên--</option>
            <?php 
				$sqlnhanvien=mysql_query("select * from tb_account_admin where level!=3");
				while($rsnhanvien=mysql_fetch_array($sqlnhanvien))
				{
			?>
            <option value="<?php echo $rsnhanvien['account_id'];?>" <?php if($_POST['nhanvien']==$rsnhanvien['account_id']){?> selected="selected" <?php }?>><?php echo $rsnhanvien['account_name'];?></option>
           <?php }?>
        </select>
    </span> 
    <?php }?>
    &nbsp;
    <span><input name="button" type="submit" value="Tìm kiếm" class="cs-title-timkiem"/></span>
    </p>
    </form>
 <div class="clear" style="height:10px"></div>
      <div class="cont-table-lich">
      <table width="100%" class="bang-baocao-llv" border="1">
 		<tr align="center" style="font-weight:bold;">
        <td  bgcolor="#92d050" style="width:3%; height:20px;" rowspan="2">STT</td>
    	<td  bgcolor="#92d050" style="width:300px; height:20px;" rowspan="2">Công việc</td>
        <td colspan="31" bgcolor="#92d050" >
        	<?php 
			$txtmonth=$_POST['txtmonth'];
			$txtyear=$_POST['txtyear'];
			$nhanvien=$_POST['nhanvien'];
			?>
    	Tháng <?php if($txtmonth!="" and $txtyear!=""){echo $txtmonth.'/'.$txtyear;}else {echo date('m/Y',time());}?>
        </td>
 		</tr>
  <tr align="center">
 	 <?php 
	 	$today=date('d',time());
  	for($j=1;$j<=31;$j++)
	{

  ?>
    <td <?php if($j==$today){echo 'bgcolor="#ff0"';}else {echo 'bgcolor="#00b0f0"';}?> class="ovuong"><?php echo $j;?></td>
   
    <?php }?>
  </tr>
     <?php 
	 $user=$_SESSION['userid'];
	 $month=date('m',time());
	 $year=date('Y',time());
  	$sqlstring="
					select * 
					from 
						register
						inner join tb_task on register.task_id= tb_task.task_id			
					where recipient='$user' and month='$month' and year='$year' and (giahan=0 or giahan=2) and (duyet_phatsinh=0 or duyet_phatsinh=2)
					";
	$sqlstring2="
					select * 
					from 
						register
						inner join tb_task on register.task_id= tb_task.task_id
					where recipient='$user' and (giahan=0 or giahan=2) and (duyet_phatsinh=0 or duyet_phatsinh=2)
					
					";
	$sqlstring3="
					select * 
					from 
						register
						inner join tb_task on register.task_id= tb_task.task_id
					
					";
	if($_SESSION['level']!==2 and $_SESSION['level']!==3)
	{
		if($txtmonth!="" and $txtyear!=""){$sqlstring2.=" and month like '%$txtmonth%' and year like '%$txtyear%'";}
		if($txtmonth!="" and $txtyear!="")
		{
		$sql=mysql_query($sqlstring2);
		}
		else
		{
			$sql=mysql_query($sqlstring);
		}
	}
	if($_SESSION['level']==2 or $_SESSION['level']==3)
	{
		if($txtmonth!="" and $txtyear!="" and $nhanvien!="")
		{
			$sqlstring3.=" and month like '%$txtmonth%' and year like '%$txtyear%' and recipient = '$nhanvien' and (giahan=0 or giahan=2) and (duyet_phatsinh=0 or duyet_phatsinh=2)";
		}
		if($txtmonth!="" and $txtyear!="" and $nhanvien!="")
		{
			$sql=mysql_query($sqlstring3);
		}
	}
	
  ?>
  
  <?php
  	$dem=1;
   while($row=mysql_fetch_array($sql))
	{
	$task_id=$row['task_id'];
	$day1=$row['date1'];
	$day2=$row['date2'];
	$day3=$row['date3'];
	$day4=$row['date4'];
	$day5=$row['date5'];
	$day6=$row['date6'];
	$day7=$row['date7'];
	$day8=$row['date8'];
	$day9=$row['date9'];
	$day10=$row['date10'];
	$day11=$row['date11'];
	$day12=$row['date12'];
	$day13=$row['date13'];
	$day14=$row['date14'];
	$day15=$row['date15'];
	$day16=$row['date16'];
	$day17=$row['date17'];
	$day18=$row['date18'];
	$day19=$row['date19'];
	$day20=$row['date20'];
	$day21=$row['date21'];
	$day22=$row['date22'];
	$day23=$row['date23'];
	$day24=$row['date24'];
	$day25=$row['date25'];
	$day26=$row['date26'];
	$day27=$row['date27'];
	$day28=$row['date28'];
	$day29=$row['date29'];
	$day30=$row['date30'];
	$day31=$row['date31'];
	?>
    	<tr>
       	<td rowspan="2" align="center"><?php echo $dem++;?> </td>
         <td rowspan="2" onclick="window.open('index.php?tn=task_detail&id=<?php echo $row['task_id'];?>','_self');" style="cursor:pointer">
            <strong> <?php echo $row['task_name'];?></strong>
          </td>
         </tr>
           <?php 
		   echo ' <tr align="center">';
		   		
            for($j=1;$j<=31;$j++)
            {
               if($_SESSION['level']==2 or $_SESSION['level']==3)
			   	{
					$sql2=mysql_query("select * from report where task_id='$task_id' and ngay=$j order by report_id desc");
				}
				else
				{
					$sql2=mysql_query("select * from report where task_id='$task_id' and ngay=$j and user_id='$user' order by report_id desc");
				}
              
                $rs=mysql_fetch_array($sql2);
             ?>
            <td class="ovuong" 
            	
				<?php if($rs['trangthai']=='1'){echo 'style="background-color:#f00"';}?>
				<?php if($rs['trangthai']=='2'){echo 'style="background-color:#f90"';} ?>
               <?php if($rs['trangthai']=='3'){echo 'style="background-color:#090"';} ?>
                <?php if($j==date('d',time()) and ($j==$day1 or $j==$day2 or $j==$day3 or $j==$day4 or $j==$day5 or $j==$day6 or $j==$day7 or $j==$day8 or $j==$day9 or $j==$day10 or $j==$day11 or $j==$day12 or $j==$day13 or $j==$day14 or $j==$day15 or $j==$day16 or $j==$day17 or $j==$day18 or $j==$day19 or $j==$day20 or $j==$day21 or $j==$day21 or $j==$day22 or $j==$day23 or $j==$day24 or $j==$day25 or $j==$day26 or $j==$day27 or $j==$day28 or $j==$day29 or $j==$day30 or $j==$day31)){?>
                onclick="window.open('index.php?tn=report&id=<?php echo $row['task_id'];?>&ngay=<?php echo $j;?>','_self');" style="background-color:#666; cursor:pointer" title="Click để báo cáo " <?php }?>><?php echo $rs['phantram'];?>
               
            	
                </td>
        <?php }
		echo ' </tr>';
		?> 
  
  <?php }?>
    
</table>
      
      </div>
      
      <p class="luuy-lichlv"><span>Lưu ý: Chỉ báo cáo những ngày hiện tại còn quá khứ và tương lai không báo cáo được nữa.</span> <strong>Ví dụ: Nếu ngày hôm nay click vào ô ngày hôm qua hoặc ngày mai để báo cáo thì không báo cáo được.</strong></p>
      </div>
  <td class="c-r"></td>
        </tr>
        <tr class="light">
          <td class="b-l"></td>
          <td class="b-c"></td>
          <td class="b-r"></td>
        </tr>
      </tbody></table>